﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SHKF.B2C.BaseHosted;
using SHKF.B2C.BLL.Center;
using SHKF.B2C.Model.Dto;
using SHKF.B2C.Model.Dto.Center;
using SHKF.B2C.Model.Entity.Center;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SHKF.B2C.Mannage.Service.Controllers
{
    [Route("[controller]")]
    [ApiController]
    public class ErpDataBaseController : BaseController
    {
        private readonly ErpServerBLL erpServerBLL;

        public ErpDataBaseController(ErpServerBLL erpServerBLL,
            ILogger<ErpServerController> logger) : base(logger)
        {
            this.erpServerBLL = erpServerBLL;
        }

        [HttpGet("list")]
        public ErpDataBaseListDto List(int fksn)
        {
            ErpDataBaseListDto dto = new ErpDataBaseListDto();
            try
            {
                List<ErpDataBaseEntity> list = this.erpServerBLL.QueryDataBase(fksn);
                dto.data = list;

            }
            catch (Exception ex)
            {
                dto.error = new Error() { code = -1, msg = ex.Message };
            }
            return dto;
        }

        [HttpPost("Save")]
        public DataDto Save(ErpDataBaseEntity data)
        {
            DataDto dto = new DataDto();

            try
            {
                this.erpServerBLL.SaveDataBase(data);
            }
            catch (Exception ex)
            {
                dto.error = new Error() { code = -1, msg = ex.Message };
            }
            return dto;
        }

    }
}
